#include "main/utils.h"
using namespace std;

int maxArea(const vector<int> &vec) {
  int max_area = 0;
  stack<int> help_stack;
  help_stack.push(-1);
  for (int i = 0; i < vec.size(); ++i) {
    while (help_stack.top() != -1 && vec[help_stack.top()] > vec[i]) {
      int top = help_stack.top();
      help_stack.pop();
      int  area = vec[top] * (i - help_stack.top() - 1);
      if (area > max_area) {
        max_area = area;
      }
    }
    help_stack.push(i);
  }
  while (help_stack.top() != -1) {
    int top = help_stack.top();
    help_stack.pop();
    int area = vec[top] * (vec.size() - help_stack.top() - 1);
    if (area > max_area) {
      max_area = area;
    }
  }
  return max_area;
}

int maxArea(const vector<vector<int>> &vec) {
  vector<int> vec_tmp(vec[0].size(), 0);
  int max_area = 0;
  for (int i = 0; i < vec.size(); ++i) {
    for (int j = 0; j < vec[i].size(); ++j) {
      if (vec[i][j] == 0) {
        vec_tmp[j] = 0;
      } else {
        ++vec_tmp[j];
      }
    }
    int cur_area = maxArea(vec_tmp);
    if (cur_area > max_area) {
      max_area = cur_area;
    }
  }
  return max_area;
}

int main() {
  vector<vector<int>> vec = {{1, 0, 1, 0, 0},
                             {0, 0, 1, 1, 1},
                             {1, 1, 1, 1, 1},
                             {1, 0, 0, 1, 0}};
  int max_area = maxArea(vec);
  cout << max_area << endl;

  return 0;
}
